<template>
    <div>
        <h4 class="font-weight-bold py-3 mb-4">
            <span class="text-muted font-weight-light">工具执行结果 /</span> 打分卡得分数据明细
        </h4>

        <hr class="border-light container-m--x mt-0 mb-5">
        <!-- <Row>
            <b-form inline>
                <label class="form-label mr-sm-2">金融产品：</label>
                <Select v-model="product.model" class="mr-sm-4" style="width:100px">
                    <Option v-for="item in product.list" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
                <label class="form-label mr-sm-2">风控节点：</label>
                <Select v-model="controlNode.model" class="mr-sm-4" style="width:100px">
                    <Option v-for="item in controlNode.list" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
                <Button @click="handleSearch" type="primary" icon="ios-search">Search</Button>
            </b-form>
        </Row> -->

        <sky-table :data="table.data" :columns="table.columns" :show-index="table.showIndex"></sky-table>

    </div>
</template>

<style scoped>
</style>

<script>
function padLeftZero (str) {
    return ('00' + str).substr(str.length);
};
function formatDate (longStr, fmt) {
   let date = new Date(longStr);

    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
        }
    }
    return fmt;
};
export default {
    name: "finalResultToolScorecardScoreDetail",
    metaInfo: {
        title: "工具执行结果 - 打分卡结果 - 明细"
    },
    data() {
        return {
            table: {
                showIndex: false,
                data: [],
                columns: [
                    {
                        title: "指标项",
                        key: "indicatorName",
                        render: (h, params) => {
                            return (
                                <div>
                                    {params.row.riskScoreIndicator.name}
                                </div>
                            );
                        }
                    },
                    {
                        title: "指标判定节点",
                        key: "riskIndicatorNodeName",
                        render: (h, params) => {
                            return (
                                <div>
                                    {params.row.riskIndicatorNode.nodeName}
                                </div>
                            );
                        }
                    },
                    {
                        title: "数据源名称",
                        key: "riskIndicatorApiMasterRelationName",
                        render: (h, params) => {
                            return (
                                <div>
                                    {params.row.riskIndicatorApiMasterRelation.aliasName}
                                </div>
                            );
                        }
                    },
                    {
                        title: "判定数据",
                        key: "apiDataId"
                    },
                    {
                        title: "数据用途",
                        key: "dataType",
                        render: (h, params) => {
                            var dataType = params.row.dataType;
                            let dataTypeName = '';
                            if(dataType == 'frontData'){
                                dataTypeName = '前置数据';
                            }else if(dataType == 'determineData'){
                                dataTypeName = '判定数据'
                            }
                            return (
                                <div>
                                    {dataTypeName}
                                </div>
                            );
                        }
                    },
                    {
                        title: "判定结果",
                        key: "determineFlag",
                        render: (h, params) => {
                            var determineFlag = params.row.determineFlag;
                            console.log("determineFlag: "+determineFlag)
                            let determineFlagName = '';
                            if(determineFlag == 1){
                                determineFlagName = '通过';
                            }else if(determineFlag == 2){
                                determineFlagName = '不通过'
                            }
                            console.log(determineFlagName)
                            return (
                                <div>
                                    {determineFlagName}
                                </div>
                            );
                        }
                    },
                    {
                        title: "记录时间",
                        key: "createDate",
                        render: (h, params) => {
                            let createDate = formatDate(params.row.createDate,'yyyy-MM-dd hh:mm:ss');
                            return (
                                <div>
                                    {createDate}
                                </div>
                            );
                        }
                    }
                ]
            },
            product:{
                list: [
                    {
                        value: "ALL",
                        label: "-- 请选择 --"
                    },
                    {
                        value: "保理产品",
                        label: "保理产品"
                    },
                    {
                        value: "控货产品",
                        label: "控货产品"
                    }
                ],
                model: "ALL",
            },
            controlNode:{
                list: [
                    {
                        value: "ALL",
                        label: "-- 请选择 --"
                    },
                    {
                        value: "入驻",
                        label: "入驻"
                    },
                    {
                        value: "授信",
                        label: "授信"
                    },
                    {
                        value: "贷前",
                        label: "贷前"
                    }
                ],
                model:"ALL"
            }
        };
    },
    mounted() {
        this.batchNo = this.$route.query.batchNo;
        this.scoreCardOid = this.$route.query.scoreCardOid;
    },
    created() {
        this.batchNo = this.$route.query.batchNo;
        this.scoreCardOid = this.$route.query.scoreCardOid;
        this.$http
            .get("/app/v1/toolRunLogs/scoreCards/"+this.scoreCardOid+"/batchNos/"+this.batchNo)
            .then(res => {
                console.log(res.data.data)
                this.table.data = res.data.data;
            });
        // // Fetch json data
        // const req = new XMLHttpRequest();
        // req.open("GET", "/static/json/finalResult/tool-scorecard-data.json");

        // req.onload = () => {
        //     const data = JSON.parse(req.response);

        //     // Add IDs for child rows functionality
        //     this.table.dataList = this.table.initTable = data;
        // };

        // req.send();
    },
    methods: {
        goDetail: function(p) {
            // console.log(p.row.name);
            alert(p.row.name);
        },
        search (data, argumentObj) {
            let res = data;
            let dataClone = data;
            for (let argu in argumentObj) {
                if (argumentObj[argu].length > 0) {
                    res = dataClone.filter(d => {
                        return d[argu].indexOf(argumentObj[argu]) > -1;
                    });
                    dataClone = res;
                }
            }
            return res;
        },
        handleSearch () {
            this.table.dataList = this.table.initTable;
            this.table.dataList = this.search(this.table.dataList, {name: this.product.model});
        }
    }
};
</script>
